<?php
require_once("../../config/config.inc.php");
$sAction = fn_getParam("strAction","");

if ($sAction=="GET_PROVINCE_LIST") {
    $sStr  = "";
    $sCode = fn_getParam("strCode","CN");
    $sql = "SELECT ID,NAME,PROVINCECITY FROM $TABLE_PROVINCE WHERE COUNTRYCODE='".$sCode."'";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $sStr .= $row["ID"]."@".$row["NAME"];
        //if (!is_null($row["PROVINCECITY"]) && $row["PROVINCECITY"]!="") {
        //  $sStr .= "(".$row["PROVINCECITY"].")";
        //}
        $sStr .= "#";
    }
    $DB->freeResult($rset);
    if ($sStr != "") $sStr = substr($sStr,0,-1);
    echo $sStr;
}
else if ($sAction=="GET_CITY_LIST") {
    $sStr  = "";
    $sProvinceID = fn_getParam("strProvinceID","");
    $sql = "SELECT ID,CODE,NAME FROM $TABLE_CITY WHERE PROVINCEID='".$sProvinceID."'";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $sStr .= $row["ID"]."@".$row["NAME"];
        //if (!is_null($row["CODE"]) && $row["CODE"]!="") {
        //  $sStr .= "(".$row["CODE"].")";
        //}
        $sStr .= "#";
    }
    $DB->freeResult($rset);
    if ($sStr != "") $sStr = substr($sStr,0,-1);
    echo $sStr; 
}
else if ($sAction=="GET_COUNTY_LIST") {
    $sStr  = "";
    $sCityID = fn_getParam("strCityID","");
    $sql = "SELECT ID,NAME,POSTCODE FROM $TABLE_COUNTY WHERE CITYID='".$sCityID."'";
    $rset= $DB->query($sql);
    while ($row = $DB->fetchRow($rset)) {
        $sStr .= $row["ID"]."@".$row["NAME"];
        //if (!is_null($row["POSTCODE"]) && $row["POSTCODE"]!="") {
        //    $sStr .= "(".$row["POSTCODE"].")";
        //}
        $sStr .= "#";
    }
    $DB->freeResult($rset);
    if ($sStr != "") $sStr = substr($sStr,0,-1);
    echo $sStr; 
}
else if ($sAction=="CHECK_EP_NAME") {
    $sEPName = fn_getParam("strEPName","");
    $sql = "SELECT COUNT(1) FROM ".$TABLE_ENTERPRISE;
    $sql.= " WHERE EPName='".$sEPName."'";
    echo $DB->getFirstField($sql);
}
else if ($sAction=="CHECK_EP_CHG_NAME") {
    $sEPName = fn_getParam("strEPName","");
    $sql = "SELECT COUNT(1) FROM ".$TABLE_ENTERPRISE;
    $sql.= " WHERE EPNAME='".$sEPName."' AND ID<>'".$SEC->sCorpCD."'";
    echo $DB->getFirstField($sql);
}
else if ($sAction=="CHECK_USER_NAME") {
    $sEPID = fn_getParam("strEPID",$SEC->sCorpCD);
    $sUserName = fn_getParam("strUserName","");
    $sql = "SELECT COUNT(1) FROM ".$TABLE_ENTERPRISE." WHERE ID=".$sEPID;
    if ($DB->getFirstField($sql)==0) {
        echo "2";
    } else {
        $sql = "SELECT COUNT(1) FROM ".$TABLE_EP_USER;
        $sql.= " WHERE EPID=".$sEPID." AND USERNAME='".$sUserName."'";
        echo $DB->getFirstField($sql);
    }
}

?>